package cn.ekuma.impexp.ui.swing;

import java.util.HashMap;
import java.util.List;

import net.sourceforge.jwizardcomponent.JWizardComponents;

import cn.ekuma.impexp.ImpExpManager;
import cn.ekuma.impexp.engine.csv.CSVEngine;
import cn.ekuma.impexp.model.ImpExpTableDefinition;

import com.openbravo.data.basic.BasicException;
import com.openbravo.data.gui.muleSelecter.MuleComboBoxValEntry;
import com.openbravo.data.loader.TableDefinition;

public class JSelectTableImportWizardPanel extends JSelectTableWizardPanel{

	public JSelectTableImportWizardPanel(JWizardComponents wizardComponents,
			List<MuleComboBoxValEntry> entrys) {
		super(wizardComponents, entrys);
	}

	@Override
	public boolean saveCurrentProperty(HashMap map) {
		MuleComboBoxValEntry selected=tableSelecter.getSelected();
		String selectFileName=txtImportFileName.getText();
		if(selected==null||selectFileName==null||selectFileName.isEmpty())
		   return false;
		ImpExpTableDefinition table=new ImpExpTableDefinition((TableDefinition) selected.getKey());
		map.put(Content.IMPORT_TABLE,table);
		map.put(Content.IMPORT_FILENAME,selectFileName);
		try {
			ImpExpManager.INSTANCE.importTableDate(table, CSVEngine.PROPERTY_prefix, selectFileName);
		} catch (BasicException e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}
}
